/*

* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Smart-Shop开源商城系统/ Java商城-首选电商平台系统 请务必保留此注释头信息
* |     开源地址: https://gitee.com/ningbo-qishan/gruul-mall
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     可正常分享和学习源码,未经授权 不可商用！
* |     商业版中台购买/开源版商业授权 联系技术客服
* |     官网:  https://www.73app.cn/
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Copyright (c) 2016-2999 宁波启山智软科技有限公司
* |     版权所有 ,侵权必究！
* ------------------------------------------------------------------------

*/
package com.medusa.gruul.platform.web.controller.agent;

import com.medusa.gruul.common.core.annotation.EscapeLogin;
import com.medusa.gruul.common.core.util.PageUtils;
import com.medusa.gruul.common.core.util.Result;
import com.medusa.gruul.platform.model.dto.agent.ListVerifyOptionDto;
import com.medusa.gruul.platform.model.vo.ListVerifyVo;
import com.medusa.gruul.platform.service.IAgentVerifyService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

/**
 * @author whh
 * @description
 * @data: 2020/10/9
 */
@RestController
@RequestMapping("/agent/admin")
@Validated
public class AgentVerifyAdminController {

    @Autowired
    private IAgentVerifyService agentVerifyService;

    @GetMapping("/listVerify")
    @EscapeLogin
    @ApiOperation(value = "审核列表查询接口", tags = "代理管理台相关")
    public Result<PageUtils<ListVerifyVo>> listVerify(@ApiParam(value = "指定页数", required = true) @RequestParam Integer page,
                                                      @ApiParam(value = "数据条数", required = true) @RequestParam Integer size,
                                                      @ApiParam(value = "审核状态 1待审核 2:审核拒绝 ", required = true) @NotNull(message = "审核状态不能为空") @Min(1) @Max(2) @RequestParam Integer status,
                                                      @ApiParam(value = "申请开始时间 2019-11-11 11:23:23") @RequestParam(required = false) String startTime,
                                                      @ApiParam(value = "申请结束时间 2019-11-11 11:23:23") @RequestParam(required = false) String endTime,
                                                      @ApiParam(value = "拒绝开始时间 2019-11-11 11:23:23") @RequestParam(required = false) String refusedStartTime,
                                                      @ApiParam(value = "拒绝结束时间 2019-11-11 11:23:23") @RequestParam(required = false) String refusedEndTime,
                                                      @ApiParam(value = "联系人或电话") @RequestParam(required = false) String search
    ) {
        PageUtils<ListVerifyVo> vos = agentVerifyService.listVerify(page, size, status, startTime, endTime, search, refusedStartTime, refusedEndTime);
        return Result.ok(vos);
    }

    @GetMapping("/{id}")
    @EscapeLogin
    @ApiOperation(value = "根据id查询指定审核记录", tags = "代理管理台相关")
    public Result<ListVerifyVo> getById(@ApiParam(value = "指定id", required = true) @PathVariable Long id) {
        ListVerifyVo vo = agentVerifyService.getByIdVo(id);
        return Result.ok(vo);
    }

    @PutMapping("/listVerify/option")
    @EscapeLogin
    @ApiOperation(value = "代理申请审核同意或拒绝", tags = "代理管理台相关")
    public Result listVerifyOption(@RequestBody ListVerifyOptionDto optionDto) {
        agentVerifyService.listVerifyOption(optionDto);
        return Result.ok();
    }

    @DeleteMapping("/verify/{id}")
    @EscapeLogin
    @ApiOperation(value = "删除已拒绝的代理审核记录", tags = "代理管理台相关")
    public Result deleteVerify(@PathVariable Long id) {
        agentVerifyService.deleteVerify(id);
        return Result.ok();
    }

}
